package com.example.easytts.service

import org.springframework.scheduling.annotation.Scheduled
import org.springframework.stereotype.Service
import java.io.File

@Service
class AudioCleanupService {
    private val audioDir = File("src/main/resources/static/audio")
    private val expireMillis = 24 * 60 * 60 * 1000L // 24小时

    // 每小时执行一次
    @Scheduled(cron = "0 0 * * * *")
    fun cleanupOldAudioFiles() {
        if (!audioDir.exists() || !audioDir.isDirectory) return
        val now = System.currentTimeMillis()
        audioDir.listFiles()?.forEach { file ->
            if (file.isFile && now - file.lastModified() > expireMillis) {
                file.delete()
            }
        }
    }
} 